package com.byd.android.agreement.message;

import com.byd.android.agreement.BaseMessage;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

import java.util.ArrayList;
import java.util.List;

public class MediaList extends BaseMessage {

    public static final int MEDIA_TYPE_MUSIC = 0x001;

    public static final int MEDIA_TYPE_VIDEO = 0x002;

    public static final String TYPE = "type";

    public static final String LIST = "list";

    public int mType;

    public List<Object> mList = new ArrayList<Object>();


    public void addToList(Object obj) {
        mList.add(obj);
    }

    public void setType(int mType) {
        this.mType = mType;
    }
    public int getType() {
        return mType;
    }

    public List<Object> getList() {
        return mList;
    }



    public static String packToJson(MediaList medialist) {
        JsonObject jobj = new JsonObject();
        jobj.addProperty(TYPE, medialist.mType);
        jobj.addProperty(LIST, mGs.toJson(medialist.mList));
        return jobj.toString();
    }

    public static JsonArray parseJson(MediaList mediaList, String jstr) {
        JsonObject jobj = mParser.parse(jstr).getAsJsonObject(); //把message.msg(格式为String)转化为JsonObj格式
        mediaList.mType = jobj.get(TYPE).getAsInt();             //用Json方式读取出Type，并转化成int整形
        System.out.println(jobj);
        String ls = jobj.get(LIST).getAsString();                //读取Json格式的MediaList中的List<Obj>，并转化为String类型
        JsonArray ja = mParser.parse(ls).getAsJsonArray();		 //把String类型的List<Obj>转化为Json格式的数组，并返回这个数组
        return ja;
    }

}
